package com.cc.base;

import com.cc.enums.HttpsCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseResult<T> implements Serializable {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 响应返回消息
     */
    private String msg;
    /**
     * 响应数据
     */
    private T data;

     /**
     * 返回成功消息
     *
     * @return
     */
    public static ResponseResult ok() {
        return new ResponseResult(200, "操作成功", null);
    }

    /**
     * 返回成功数据
     *
     * @return 成功消息
     */
    public static <T> ResponseResult<T> ok(T data) {
        return new ResponseResult<T>(200, "操作成功", data);
    }

    /**
     * 返回错误消息
     *
     * @param msg 返回内容
     * @return 警告消息
     */
    public static <T> ResponseResult<T> error(String msg) {
        return new ResponseResult<T>(500, msg, null);
    }

    /**
     * 返回错误消息
     * @param code
     * @param msg
     * @return
     */
    public static ResponseResult<String> error(Integer code, String msg) {
        return new ResponseResult<String>(code, msg, null);
    }

    /**
     * 返回错误消息
     *
     * @param httpsCode
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<String> error(HttpsCode httpsCode) {
        return new ResponseResult<String>(httpsCode.getCode(), httpsCode.getMessage(), httpsCode.getDescription());
    }
}
